package com.asura.app.library.utils;

import android.content.Context;
import android.content.SharedPreferences;

/**
 * Created by Asura on 2016/8/9.
 */
public final class PreferenceHelper {

    private final SharedPreferences mSharedPreferences;
    private final SharedPreferences.Editor mEditor;

    public PreferenceHelper(Context context, String name) {
        mSharedPreferences = context.getSharedPreferences(name, Context.MODE_PRIVATE);
        mEditor = mSharedPreferences.edit();
    }

    public Boolean get(String key, Boolean defaultValue) {
        return mSharedPreferences.getBoolean(key, defaultValue);
    }

    public String get(String key, String defaultValue) {
        return mSharedPreferences.getString(key, defaultValue);
    }

    public int get(String key, int defaultValue) {
        return mSharedPreferences.getInt(key, defaultValue);
    }

    public long get(String key, long defaultValue) {
        return mSharedPreferences.getLong(key, defaultValue);
    }

    public float get(String key, float defaultValue) {
        return mSharedPreferences.getFloat(key, defaultValue);
    }

    public PreferenceHelper put(String key, Boolean value) {
        mEditor.putBoolean(key, value).apply();
        return this;
    }

    public PreferenceHelper put(String key, String value) {
        mEditor.putString(key, value).apply();
        return this;
    }

    public PreferenceHelper put(String key, int value) {
        mEditor.putInt(key, value).apply();
        return this;
    }

    public PreferenceHelper put(String key, long value) {
        mEditor.putLong(key, value).apply();
        return this;
    }

    public PreferenceHelper put(String key, float value) {
        mEditor.putFloat(key, value).apply();
        return this;
    }

}
